import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { persistStore, persistReducer } from 'redux-persist'
//  存储机制 localStorage 会永久存于本地， sessionStorage 当当前浏览器标签关闭的时候则会清除
import storage from 'redux-persist/lib/storage'
// import sessionStorage from 'redux-persist/es/storage/session'

import reducers from './reducers'
import Sagas from './sagas'

// saga中间件
const sagaMiddleware = createSagaMiddleware()
// 数据对象
const storageConfig = {
    key: 'root', // 必须有的
    storage:storage, // 缓存机制
    // blacklist: ['name','age'] // reducer 里不持久化的数据,除此外均为持久化数据 黑名单
    whitelist:['PublicReducer', 'UserInfoReducer']  //白名单, 直接写入reduce暴露的那些模块就好
}

const myPersistReducer = persistReducer(storageConfig, reducers)
// 暴露store
// export default createStore(reducers, applyMiddleware(sagaMiddleware))
const store = createStore(myPersistReducer,applyMiddleware(sagaMiddleware))

export const persistor = persistStore(store)
export default store
// saga必须得run一下
sagaMiddleware.run(Sagas)